/************************************************************
function GetDistrictName
************************************************************/

if exists 
  (
      select * from dbo.sysobjects 
      where id = object_id(N'GetDistrictName') 
  )
  drop function [dbo].GetDistrictName
GO

create function [dbo].GetDistrictName
(
    @id int
)
returns nvarchar(50)
as 
begin

    declare @name nvarchar(50)

    select @name=[districtname] 
	    from [district]
	    where [id]=@id

    return @name

end
GO

/************************************************************
function GetSymptomName
************************************************************/
IF EXISTS 
  (
      select * from dbo.sysobjects 
      where id = object_id(N'GetSymptomName') 
  )
  DROP FUNCTION [dbo].GetSymptomName
GO

CREATE FUNCTION [dbo].GetSymptomName
(
    @id int
)
returns nvarchar(50)

AS 
BEGIN
    declare @name nvarchar(50)

    select @name=[symptomname] 
	    from [Symptom]
	    where [id]=@id

    return @name

end

GO


/************************************************************
function GetTreatmentName
************************************************************/
IF EXISTS 
  (
      select * from dbo.sysobjects 
      where id = object_id(N'GetTreatmentName') 
  )
  DROP FUNCTION [dbo].GetTreatmentName
GO

CREATE FUNCTION [dbo].GetTreatmentName
(
    @id int
)
returns nvarchar(50)

AS 
BEGIN
    declare @name nvarchar(50)

    select @name=[TreatmentName] 
	    from [Treatment]
	    where [id]=@id

    return @name

end

GO


/************************************************************
function GetDiseaseName
************************************************************/
IF EXISTS 
  (
      select * from dbo.sysobjects 
      where id = object_id(N'GetDiseaseName') 
  )
  DROP FUNCTION [dbo].GetDiseaseName
GO

CREATE FUNCTION [dbo].GetDiseaseName
(
    @id int
)
returns nvarchar(50)

AS 
BEGIN
    declare @name nvarchar(50)

    select @name=[DiseaseName] 
	    from [Disease]
	    where [id]=@id

    return @name

end

GO


/************************************************************
function GetUserAvatar
************************************************************/

IF EXISTS 
  (
      SELECT * from dbo.sysobjects 
      WHERE id = object_id(N'GetUserAvatar') 
  )
  DROP FUNCTION [dbo].GetUserAvatar
GO

CREATE FUNCTION [dbo].GetUserAvatar
(
    @Id int
)
RETURNS nvarchar(50)
AS 
BEGIN

IF @Id > 0
	BEGIN
		DECLARE @name nvarchar(50)

		SELECT 
			@name=[Avatar] 
		FROM 
			[UserInfo]
		WHERE 
			[id]=@id

		return @name
	END

return ''

END

GO